package com.itheima.demo.callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test01 {//扩展性好,还可继承其他接口,编程相对复杂,不能直接使用Thread中的方法,有参
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //线程创建后要执行里面的call方法
        MyCallable mc =new MyCallable();
        //可获得线程执行完后的结果,也可作为参数传递给Thread对象
        FutureTask<String> ft1 = new FutureTask<String>(mc);
        FutureTask<String> ft2 = new FutureTask<String>(mc);
        Thread t1= new Thread(ft1);
        Thread t2= new Thread(ft2);
        //开启线程
        t1.start();
        t2.start();
        System.out.println(ft1.get());
        System.out.println(ft2.get());
    }
}
